//
//  LFHttpclient.m
//  LocalLife
//
//  Created by 李立达 on 15/11/23.
//  Copyright © 2015年 heima11. All rights reserved.
//

#import "LFHttpclient.h"
#import "LFHomeModel.h"
@implementation LFHttpclient
+(id)shareInstense
{
    static LFHttpclient *client=nil;
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        client=[[LFHttpclient alloc]initWithBaseURL:[NSURL URLWithString:@"http://www.qd-life.com/"]];
        client.responseSerializer=[AFHTTPResponseSerializer serializer];
    });
    return client;
}
//示例方法 发送网络请求
+(void)httpGetWithUrl:(NSString *)url WithPamter:(NSDictionary *)pamter WithSucessBlock:(sucessloadData)sucess WitherrorBlock:(errorloadData)errorload
{
    return [[LFHttpclient shareInstense]httpGetWithUrl:url WithPamter:pamter WithSucessBlock:sucess WitherrorBlock:errorload];
}
-(void)httpGetWithUrl:(NSString *)url WithPamter:(NSDictionary *)pamter WithSucessBlock:(sucessloadData)sucess WitherrorBlock:(errorloadData)errorload
{
    [self GET:url parameters:pamter success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        
        sucess(responseObject);
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        errorload(error);
    }];
}
//示例方法发送首页返回数据请求
+(void)httpGetHomeWithUrl:(NSString *)url WithPamter:(NSDictionary *)pamter
          WithSucessBlock:(sucessloadData)sucess WitherrorBlock:(errorloadData)faild
{
    [[LFHttpclient shareInstense]httpGetHomeWithUrl:url WithPamter:pamter WithSucessBlock:sucess WitherrorBlock:faild];
}
-(void)httpGetHomeWithUrl:(NSString *)url WithPamter:(NSDictionary *)pamter
          WithSucessBlock:(sucessloadData)sucess WitherrorBlock:(errorloadData)faild
{
    [self httpGetWithUrl:url WithPamter:pamter WithSucessBlock:^(id JSON) {
        
        NSString *path=[[NSBundle mainBundle]pathForResource:@"home" ofType:@"plist"];
        
        NSDictionary *dict=[[NSDictionary alloc]initWithContentsOfFile:path];
        
        
        LFHomeModel *modle=[[LFHomeModel alloc]initWithDictionary:dict error:nil];
        sucess(modle);
    } WitherrorBlock:faild];
}
@end
